import scala.io.StdIn

object Fibonacci {
  def main(args: Array[String]): Unit = {
    println("请输入一个正整数N：")
    val n = StdIn.readInt()

    if (n <= 0) {
      println("请输入一个正整数！")
    } else {
      val fibs = fibonacci(n)
      println(fibs.mkString(", "))
    }
  }

  def fibonacci(n: Int): List[Int] = {
    @annotation.tailrec
    def fibHelper(a: Int, b: Int, count: Int, acc: List[Int]): List[Int] = {
      if (count == 0) acc
      else fibHelper(b, a + b, count - 1, acc :+ a)
    }
    fibHelper(1, 1, n, List())
  }
}